$(function(){
	$('#ss').searchbox({
		value:$.cookie('keywords'),
	    searcher:function(value){
			var a = document.createElement("a");
	    	if(value == null || value == "" || typeof value == "undefined"){
	    		a.href = "/filesharingsystem/main";
	    	}else{
	    		a.href = "/filesharingsystem/search?keywords="+value;
	    	}
			a.click();
	    },
		width:'420',
		border:false,
		height:'34',
	    prompt:'Please Input Value'
	});
	$('#p').panel({
		width:540,
		height:'auto',
		border:false,
		href:'search_result?page=1&rows=10&keywords='+$.cookie('keywords'),
		extractor:function(data){
			
			var obj = JSON.parse(data);
			var files = obj.rows;
			var str ="";		
			if(obj.total < 1){
				return "很抱歉，没有找到与“<font color=red>"+$.cookie('keywords')+"</font>”相关的内容";
			}
			var times;
			if(obj.total-obj.offset<10){
				times = obj.total-obj.offset;
			}else{
				times = 10;
			}
			
			for(var i=0; i<times; i++){
				str +=  	"<div style='width:538px;margin-bottom:14px;'>";
				str +=			"<h3 style='margin: 0px;'><a href='"+files[i].link+"'>"+files[i].fileName+"</a></h3>";
				str +=			"<div>";
				str +=				"<span>";
				str +=					files[i].notes;
				str +=				"</span>";
				str +=			"</div>";
				str +=			"<div>"; 
				str +=				"<span style='margin-right: 20px;'>"+"<font color='#828282'>提供者:</font>"+files[i].provider+"</span>";
				str +=				"<span style='margin-right: 20px;'>"+"<font color='#828282'>文件类型:</font>"+files[i].type+"</span>";
				str +=				"<span>"+"<font color='#828282'>文件大小:</font>"+files[i].size+"/byte"+"</span>";
				str +=			"</div>";
				str +=		"</div>";	
			}
			$(".query-count").text("我们为您找到相关结果约"+obj.total+"个");
			$('#pp').pagination({
				layout:['sep','prev','next','links'],
				beforePageText:'Go Page',
				afterPageText:'',
				pageSize:10,
				total:obj.total,
				onSelectPage:function(pageNumber, pageSize){
					$('#p').panel('refresh', 'search_result?page='+pageNumber+'&rows=10&keywords='+$.cookie('keywords'));
				}
			});
			return str;
		}
	});
	$(".nabla").mouseenter(function(){
		$("#info-panel").toggle();
	});
	$(".nabla").mouseout(function(){
		$("#info-panel").hide();
	});
	setCurrentUser();
})
function setCurrentUser(){
	$.get('user',function(data){
		$(".current-user-name").text(data.username);
		$(".level").text(data.role.roleName);

		
		$("#info1").html("用户名:"+data.username);
		$("#info2").html("邮&nbsp;&nbsp;&nbsp;箱:"+data.email);
		$("#info3").html("身&nbsp;&nbsp;&nbsp;份:"+data.role.roleName);
		$("#info4").html("状&nbsp;&nbsp;&nbsp;态:"+(data.state>0?"正常":"禁用"));
		$("#info5").html("注册于:"+data.regDate);
	},"json");	
}